#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QPushButton>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_pushButton_clicked()
{
    //创建QMessageBox
    QMessageBox* messageBox=new QMessageBox(this);
    messageBox->setWindowTitle("标题");
    messageBox->setText("对话框文本");
    messageBox->setIcon(QMessageBox::Warning);

    //创建自定义按钮
    QPushButton* button=new QPushButton("自定义按钮",messageBox);


    //messageBox->addButton(button,QMessageBox::AcceptRole);

    messageBox->addButton(button,QMessageBox::RejectRole);


    messageBox->setStandardButtons(QMessageBox::Ok|QMessageBox::Save|QMessageBox::Cancel);
    int result=messageBox->exec();//通过exec返回值可以知道用户按下哪个按钮
    if(result==QMessageBox::Ok)
    {
        qDebug()<<"ok";
    }
    delete messageBox;//模态,可以直接删

}
